﻿<Window x:Class="ScrumFactory.Tasks.UserTasksSelector"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:PresentationOptions="http://schemas.microsoft.com/winfx/2006/xaml/presentation/options"
        xmlns:props="clr-namespace:ScrumFactory.Tasks.Properties"
        xmlns:SF_Helpers="clr-namespace:ScrumFactory.Windows.Helpers;assembly=ScrumFactory.Windows.Helpers"
        
        x:Name="thisView"
        Title="UserTasksSelector"
        ShowInTaskbar="False"
        Topmost="True"
        AllowsTransparency="True" Background="#01000000"  IsHitTestVisible="True"     
        WindowStyle="None"
        
         UseLayoutRounding="True"
        SnapsToDevicePixels="True"

        Height="500" Width="360">
    <Window.Resources>

        <Storyboard x:Key="ClockStoryboard" PresentationOptions:Freeze="True">
            <DoubleAnimation                
                Storyboard.TargetProperty="(Path.RenderTransform).(RotateTransform.Angle)"
                From="0"
                To="360"
                Duration="0:0:1"
                RepeatBehavior="Forever" />
        </Storyboard>
        
    </Window.Resources>

    <Grid VerticalAlignment="Stretch" >
       
            <ListBox       
                x:Name="taskList"                
                VerticalAlignment="Bottom" IsHitTestVisible="True"                                
                ItemsSource="{Binding Tasks}">
                <ListBox.ItemTemplate>
                    <DataTemplate>
                    <Border Margin="0,3,0,3"   Cursor="Hand" Style="{StaticResource PostItBorder}" BorderThickness="2">
                            <Grid HorizontalAlignment="Stretch">
                                <Grid.ColumnDefinitions>
                                    <ColumnDefinition Width="30"/>
                                    <ColumnDefinition Width="240"/>
                                    <ColumnDefinition Width="70"/>
                            </Grid.ColumnDefinitions>
                            <Grid.RowDefinitions>
                                <RowDefinition Height="*"/>                                
                            </Grid.RowDefinitions>

                            

                            <StackPanel 
                                Grid.Column="0" 
                                Orientation="Vertical" HorizontalAlignment="Center" VerticalAlignment="Center" >
                                <Path  Fill="{StaticResource TrackClockBrush}" HorizontalAlignment="Center">
                                    <Path.Data>
                                        <PathGeometry>
                                            <PathFigure StartPoint="12 0"  IsClosed="True">
                                                <ArcSegment Size="12 12" Point="24 12" SweepDirection="Clockwise" />
                                                <LineSegment Point="12 12" />
                                            </PathFigure>
                                        </PathGeometry>
                                    </Path.Data>
                                    <Path.RenderTransform>
                                        <RotateTransform Angle="0" CenterX="12" CenterY="12"/>
                                    </Path.RenderTransform>
                                    <Path.Style>
                                        <Style>
                                            <Style.Triggers>
                                                <DataTrigger Binding="{Binding IsTracking}" Value="True">
                                                    <DataTrigger.EnterActions>
                                                        <BeginStoryboard x:Name="clockStory" Storyboard="{StaticResource ClockStoryboard}"/>
                                                    </DataTrigger.EnterActions>
                                                    <DataTrigger.ExitActions>
                                                        <StopStoryboard BeginStoryboardName="clockStory"/>
                                                    </DataTrigger.ExitActions>
                                                </DataTrigger>
                                                <DataTrigger Binding="{Binding IsTracking}" Value="False">
                                                    <Setter Property="Path.Visibility" Value="Hidden"/>
                                                </DataTrigger>
                                            </Style.Triggers>
                                        </Style>
                                    </Path.Style>
                                </Path>
                                <TextBlock
                                        Margin="0,10,0,0" TextWrapping="Wrap" HorizontalAlignment="Center" TextAlignment="Center"
                                        Text="{Binding FormatedEllipsedHours}" FontSize="{StaticResource TinyFontSize}">
                                        <TextBlock.Style>
                                            <Style>
                                                <Style.Triggers>
                                                    <DataTrigger Binding="{Binding IsTracking}" Value="False">
                                                        <Setter Property="TextBlock.Visibility" Value="Hidden"/>
                                                    </DataTrigger>
                                                </Style.Triggers>
                                            </Style>
                                        </TextBlock.Style>
                                </TextBlock>
                            </StackPanel>

                            <DockPanel VerticalAlignment="Top" HorizontalAlignment="Center"                            
                                Grid.Column="0" Style="{StaticResource ItemActionMenu}" >
                                <Button Grid.Column="0" Grid.RowSpan="2"
                                    Style="{StaticResource CleanButton}"
                                    Command="{Binding TrackTaskCommand}"
                                    HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Width="24" Height="24">

                                    <Image Source="/Images/Toolbar/clock.png" Width="24" Height="24">
                                        <Image.Style>
                                            <Style>
                                                <Style.Triggers>
                                                    <DataTrigger Binding="{Binding IsTracking}" Value="True">
                                                        <Setter Property="Image.Visibility" Value="Hidden"/>
                                                    </DataTrigger>
                                                </Style.Triggers>
                                            </Style>
                                        </Image.Style>
                                    </Image>
                                </Button>                                
                            </DockPanel>

                            <!-- strange bind stuff go heres, but can not pass "me" as command parameter
                                cus somehow it messup the GC and "me" is never collected -->
                            <DockPanel VerticalAlignment="Center" HorizontalAlignment="Center"                            
                                Grid.Column="2" Style="{StaticResource ItemActionMenu}" >
                                <Button 
                                            DockPanel.Dock="Left" VerticalAlignment="Center" Margin="0,0,5,0"
                                            Style="{StaticResource CleanButton}"
                                            Command="{Binding CopyTaskTrackIdCommand}" 
                                            ToolTip="{x:Static props:Resources.copy_track_info_to_clipboard}">
                                    <Image Source="/Images/Toolbar/tag.png" Width="24" Height="24"/>
                                </Button>
                                <Button 
                                    HorizontalAlignment="Center" VerticalAlignment="Center"
                                    Style="{StaticResource CheckButton}"                                        
                                    Command="{Binding ShowFinishDialogCommand}"/>
                                
                            </DockPanel>


                            <StackPanel Grid.Column="1" Grid.Row="0" Orientation="Vertical">
                                <TextBlock
                                        Style="{StaticResource ItemTitleTextBlock}" FontSize="{StaticResource NormalFontSize}" 
                                        Text="{Binding Task.TaskName}"/>
                                <DockPanel>                                    
                                    <TextBlock
                                                DockPanel.Dock="Left"
                                                FontSize="{StaticResource SmallFontSize}"
                                                Foreground="{StaticResource LinkBrush}" Margin="0,0,0,0" VerticalAlignment="Center"
                                                Text="{Binding Task, Converter={StaticResource TaskTrackIdConverter}}"/>
                                    <TextBlock Margin="5,0,0,0">
                                        <Hyperlink Command="{Binding DataContext.ShowTaskDetailCommand, ElementName=thisView}"
                                                   CommandParameter="{Binding .}" >
                                            <TextBlock Text="{x:Static props:Resources.Details}" FontSize="{StaticResource SmallFontSize}" />
                                        </Hyperlink>
                                    </TextBlock>

                                    <Image 
                                            DockPanel.Dock="Right" HorizontalAlignment="Right" Margin="3"
                                            DataContext="{Binding Task.TaskType}"  Style="{StaticResource TaskTypeOnPostItImage}"/>
                                </DockPanel>

                            </StackPanel>

                        </Grid>
                            
                        </Border>                 
                    </DataTemplate>
                </ListBox.ItemTemplate>
            <ListBox.ItemContainerStyle>
                <Style TargetType="{x:Type ListBoxItem}">
                    <Setter Property="Template">
                        <Setter.Value>
                            <ControlTemplate TargetType="ListBoxItem">
                                <ContentPresenter x:Name="content" />                                
                            </ControlTemplate>
                        </Setter.Value>
                    </Setter>
                </Style>
            </ListBox.ItemContainerStyle>
        </ListBox>

            
       
        <ContentControl Style="{StaticResource LoadingAnimationContent}" VerticalAlignment="Bottom" />
    </Grid>
    
    
</Window>
